package cn.ecut.servletcontext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author lujiapeng
 * @className GetServletContextServlet
 * @description TODO
 * @date 2020/9/11 16:40
 **/
@WebServlet("/applicationInitParamter")
public class ApplicationInitServlet extends HttpServlet  {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1、获取到具体的ServletContext
        ServletContext application = this.getServletContext();

        // 2、获取 全局的初始化参数
        Enumeration<String> initParameterNames = application.getInitParameterNames();
        while( initParameterNames.hasMoreElements() ){
            String s = initParameterNames.nextElement();
            String parameter = application.getInitParameter(s);
            System.out.println( parameter );
        }
    }
}
